﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using CommonLib;

namespace TrackingClient
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {

            
        }

        PacketProtocol objPacket;
        private void button1_Click(object sender, EventArgs e)
        {
            objPacket = new PacketProtocol();
            
            // header for packet from tracking unit to server
            objPacket._header = BitConverter.GetBytes((ushort)enumHeader.FromTracking);//new byte[] { 0x24, 0x24 };

            //id in hex code: 12345678, unused bytes is 'f' or '0xff'
            objPacket._id = new byte[] {0x13, 0x61, 0x23, 0x45, 0x67, 0x8f, 0xff }; 
            
            //command Tradker's login: 0x5000
            objPacket._command = BitConverter.GetBytes((ushort)enumCommand.Tracker_Login); ; // new byte[] { 0x00, 0x50 };

            //create data
            string username = "hgtuan2003";
            string password = "123456";
            objPacket._data = Encoding.ASCII.GetBytes(string.Format("{0};{1}", username, password));
            
            // The end character \r\n
            //objPacket._end = new byte[] { 0x0d, 0x0a }; 
            
            //objPacket.CalculateCheckSum();
            //textBox2.Text = BitConverter.ToString(objPacket._checksum);

            
            //objPacket._checksum.CopyTo(testVal, objPacket._header.Length + objPacket._length.Length + objPacket._id.Length + objPacket._command.Length);

            
        }

        private void button2_Click(object sender, EventArgs e)
        {
            objPacket = new PacketProtocol();
            objPacket._header = Encoding.ASCII.GetBytes("2");
            objPacket._header = BitConverter.GetBytes((short)2);
            //string i = BitConverter.ToString(bytes);
            //textBox1.Text = i;
            //string value  = ""
            //PacketProtocol objPacket = new PacketProtocol("12345678", "AC", "Test Data");
        }
    }
}
